function [OUT_Bits] = HF_Convenc_Tailbiting_K7_Punct_R43(IN_Bits,t)

%*----------------------------- HF_Convenc_Tailbiting_K7_Punct_R43 -----------------------------%
% [OUT_Bits] = HF_Convenc_Tailbiting_K7_Punct_R43(IN_Bits)
%
% HF Convolutional Encoding (Tail biting with k=7) and Punctured with the
% final Rate = 4/3.
%
%*----------------------------------------------------------------------------------------------------%

%*------------------------------------------ INITIALIZATIONS ---------------------------------------%
% PADDING the IN_Bits to be suitable for Matlab (Convenc) function with puncturing.
K = 7;
PAD =0;
if mod(length(IN_Bits),(K-1)) ~=0
    PAD = (K-1)-mod(length(IN_Bits),(K-1));
end
IN_Bits = [IN_Bits zeros(1,PAD)];
punc_vec = [1 1 1 0 0 1];  % puncturing pattern

%*----------------------------------------------------------------------------------------------------%

%*--------------------------------- CONVOLUTIONAL ENCODER ---------------------------------------%
% t = poly2trellis(K, [Generator1 Generator2]); % Define trellis.
INIT_State = bin2dec(num2str(fliplr(IN_Bits(1:(K-1))))); %Define an initial state for the encoder to  
% simulate the tail biting. (state is the first 6 bits in the block and reprented in decimal)

MSG = [IN_Bits(K:end) IN_Bits(1:(K-1))]; % format the MSG to be suitable for tail biting encoding.

OUT_Bits = convenc(MSG,t,punc_vec,INIT_State); % Encode the data.
%*----------------------------------------------------------------------------------------------------%

